import { defineStore } from 'pinia';

export const ToastStore = defineStore('toast', {
    state: () => {
        return {
            list: [
                { titles: "首页", paths: "/home" }
            ],
        }
    },
    getters: {},
    actions: {
        addList(payload) {
            let a = [];
            let b = 0;
            for (let i = 0; i < this.list.length; i++) {
                if (this.list[i].titles == payload.titles) {
                    a.push(true);
                } else {
                    a.push(false)
                }
            }
            a.forEach(item => {
                if (!item) {
                    b++
                }
            });
            if (b == a.length) {
                this.list.push(payload);
            }
        },
        deleList(payload) {
            let idx = -1;
            this.list.forEach((item, index) => {
                if (item.paths == payload) {
                    idx = index
                }
            });
            this.list.splice(idx, 1);
        }
    },
    // 数据持久化
    // persist: {
    //     enabled: true
    // }
})